package com.sunkq.juc;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @Auther: longy
 * @Date: 2020/12/26/12:32
 * @Description:
 */
public class CyclicBarrierDemo {
    public static void main(String[] args) {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(7, () -> {
//            while(true) {
                System.out.println(Thread.currentThread().getName() + "\t召唤神龙......");
//            }
        });

        for (int i = 1; i <= 7; i++) {
            final int temp = i;
            new Thread(() ->{
                while(true){
                    System.out.println(Thread.currentThread().getName() + "\t收集到,第：" + temp + "颗龙珠");
                    try {
                        cyclicBarrier.await();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            },"线程"+String.valueOf(i)).start();
        }
    }
}
